<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>链式编程</title>
</head>

<body>

</body>
<script>
  "use strict";
  const Skill = class {
    constructor(person) {
      this.person = person;
    }
    withLevel(level) {
      this.level = level;
      return this;
    }
    withTag(tag) {
      this.tag = tag;
      return this;
    }
    end() {
      return this.person;
    }
  }
  const Person = class {
    // constructor(name, age) {
    //   this.name = name;
    //   this.age = age;
    // }
    withAge(age) {
      this.age = age;
      return this;
    }
    withName(name) {
      this.name = name;
      return this;
    }
    withSkill() {
      return new Skill(this);
    }
  };


  let son = new Person().withAge(20).withName('大卫').withSkill().withTag('Sing').withLevel(5).end().withName('刀哥');

  console.log(son);
</script>

</html>